<template>
  <div class="login_page">
    <!-- offset:偏移量,向右移动的格数 -->
    <!-- span:自己占有的格数 -->
    <el-col :span="8" :offset="8">
      <div class="grid-content bg-purple">
        <h4>小U商城后台管理系统</h4>
        <!-- model:表单的数据 -->
        <!-- rules:表单的校验规则 -->
        <el-form
          :model="ruleForm"
          :rules="rules"
          ref="ruleForm"
          class="demo-ruleForm"
          
        >
          <el-form-item label="用户名" prop="username">
            <el-input v-model="ruleForm.username"
              ><i class="el-icon-user-solid"></i
            ></el-input>
          </el-form-item>

          <el-form-item
            label="密码"
            prop="password"
            prefix-icon="iconfont el-icon-user-solid"
          >
            <el-input v-model="ruleForm.password" show-password></el-input>
          </el-form-item>
        </el-form>
        <el-button type="primary" @click="submitForm('ruleForm')"
          >立即登录</el-button
        >
      </div>
    </el-col>
    <!-- </el-row> -->
  </div>
</template>

<script>
// import { userLogin } from "../api";
export default {
  data() {
    return {
      labelPosition: "right",
      ruleForm: {
        username: "123456",
        password: "123456",
      },
      rules: {
        username: [
          { required: true, message: "请输入手机号", trigger: "blur" },
          {
            min: 3,
            max: 10,
            message: "长度在 6 到 10 个字符",
            trigger: "blur",
          },
        ],
        password: [
          { required: true, message: "请输入密码", trigger: "blur" },
          {
            min: 3,
            max: 10,
            message: "长度在 6 到 10 个字符",
            trigger: "blur",
          },
        ],
      },
    };
  },
  methods: {
    submitForm(formName) {
      // this.$refs.ruleForm.validate((valid) => {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          // console.log(this.ruleForm);
          /*  let res = await userLogin(this.ruleForm);
          console.log(res); */
          this.$http
            .post("/userLogin", this.ruleForm)
            .then((res) => {
              if (res.code === 200) {
                //登陆成功,保存用户数据，跳转到首页
                this.$store.commit("savaUserInfo", res.list);
                this.$router.push("/");
              } else {
                // 失败
                this.$message({
                  type: "error",
                  message: res.msg,
                });
              }
            })
            .catch((err) => {
              console.log(err);
            });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  },
};
</script>


<style lang="less" scoped>
.login_page {
  width: 100%;
  height: 100vh;
  background: url("../assets/loginbg.jpeg");
}

.el-col {
  border-radius: 4px;
}
.bg-purple-dark {
  background: #99a9bf;
}
.bg-purple {
  background: #fff;
}
.grid-content {
  margin-top: 100px;
  border-radius: 4px;
  min-height: 80px;
  padding: 16px 20px 15px;
  h4 {
    text-align: center;
    font-size: 18px;
    letter-spacing: 2px;
    color: #fb7849;
  }
  .el-form-item {
    text-align: center;
  }
  .el-button {
    width: 100%;
    background: #fb6d49;
    border: 1px solid #fb6d49;
  }
}
</style>

